﻿using Pumpkin.Utils;
using UnityEngine;

namespace Pumpkin.FrameBase
{
    public class GlobalConfigs : Singleton<GlobalConfigs>
    {
        private string ResServerUrl;
        private bool IsDebug;
        private bool EnableHotFix;
        private string GlobalObjectName = "GlobalObject";
        private GameObject GlobalObject;

        public void SetResUrl(string url)
        {
            ResServerUrl = url;
        }

        public void SetMode(bool isDebug)
        {
            IsDebug = isDebug;
        }

        public void SetUseHotFix(bool enableHotFix)
        {
            EnableHotFix = enableHotFix;
        }

        public void SetGlobalObjectName(string globalObjName)
        {
            GlobalObjectName = globalObjName;
            if(GlobalObject != null)
            {
                GlobalObject.name = globalObjName;
            }
        }

        public GameObject GetGlobalObject()
        {
            if(GlobalObject == null)
            {
                GlobalObject = new GameObject() { name = GlobalObjectName };
                GameObject.DontDestroyOnLoad(GlobalObject);
            }

            return GlobalObject;
        }

        public string GetVersionUri()
        {
            //return FileHelper.CombinePath(ResServerUrl, VersionFile);
            return ResServerUrl + HotFixConfigs.VersionFile;
        }

        public string GetResVersionUri()
        {
            return ResServerUrl + HotFixConfigs.ResVersionFile;
        }

        public string GetFileTableUri()
        {
            return ResServerUrl + HotFixConfigs.BundleFileTable;
        }

        public string GetBundleUri(string bundleName)
        {
            return ResServerUrl + HotFixConfigs.BundleRootDir + "/" + bundleName;
        }

        public string GetExt2Name2PathUri()
        {
            return ResServerUrl + HotFixConfigs.Ext2File2PathFile;
        }

        public bool IsDebugMode()
        {
            return IsDebug;
        }

        public bool HotFixEnabled()
        {
            return EnableHotFix;
        }
    }
}
